<template>
	<view class="main">
	    <button class="specialthanks achievement-back-btn"  @tap="navBack">返回</button>
	    <text class="title">统计</text>
	    <view class="total view-ul">
			<view class="view-li" :class="[totalGradeCls('times', total.times)]"><text class="achievementtitle">已重开{{total.times}}次</text>{{formatRate('times', total.times)}}</view>
			<view class="view-li" :class="[totalGradeCls('achievement', total.achievement)]"><text class="achievementtitle">成就达成{{total.achievement}}个</text>{{formatRate('achievement', total.achievement)}}</view>
			<view class="view-li" :class="[totalGradeCls('eventRate', total.eventRate)]"><text class="achievementtitle">事件收集率</text>{{Math.floor(total.eventRate * 100)}}%</view>
			<view class="view-li" :class="[totalGradeCls('talentRate', total.talentRate)]"><text class="achievementtitle">天赋收集率</text>{{Math.floor(total.talentRate * 100)}}%</view>
		</view>
	    <text style="padding:0.25rem; margin: 0.5rem 0; border: none; background: #ccc;"></text>
	    <view class="title">成就<button class="rank" @tap="showRank">排行榜</button></view>
	    <view  class="achievements view-ul">
			<view v-for="(item,aix) in achievements" :key="aix" class="view-li" :class="item.cls"><text class="achievementtitle">{{item.name}}</text>{{item.description}}</view>
		</view>
	</view>
</template>

<script>
	import { getRate, getGrade } from '../../lib/lifeRestart/core/functions/addition.js';
	export default {
		data() {
			return {
				achievements:[],
				total:{
					times: 0,
					achievement:0,
					eventRate:0,
					talentRate:0
				},
				firstShow:true
			}
		},
		onLoad() {
			this.refresh();
			this.firstShow = true;
		},
		onShow() {
			if(!this.firstShow){
				this.refresh();
			}
			this.firstShow = false;
			
		},
		methods: {
			refresh(){
				this.total =  getApp().globalData.lifeRestart.app.getTotal();
				let achievementsData =  getApp().globalData.lifeRestart.app.getAchievements();
				let achievements = [];
				achievementsData.forEach(({
								name, description, hide,
								grade, isAchieved
							})=>{
								console.log(hide,isAchieved,"testst");
								if(hide && !isAchieved) name = description = '???';
								achievements.push({
										grade:grade,
										isAchieved:isAchieved,
										cls:"achvg"+grade+" "+(isAchieved?"":"mask"),
										name:name,
										description:description
									}
									
								);
							});
				this.achievements = achievements;
			},
			showRank(){
				uni.showModal({
					title:"哈哈哈",
					content:"别卷了，没有排行榜",
					showCancel:false,
					confirmText:"ok"
				})
			},
			totalGradeCls(code,value){
				return "achvg"+getGrade(code, value) ;
			},
			formatRate(type,value){
				const rate = getRate(type, value);
				let color = Object.keys(rate)[0];
				switch(parseInt(color)) {
				    case 0: color = '白色'; break;
				    case 1: color = '蓝色'; break;
				    case 2: color = '紫色'; break;
				    case 3: color = '橙色'; break;
				    default: break;
				}
				let r = Object.values(rate)[0];
				switch(parseInt(r)) {
				    case 1: r = '不变'; break;
				    case 2: r = '翻倍'; break;
				    case 3: r = '三倍'; break;
				    case 4: r = '四倍'; break;
				    case 5: r = '五倍'; break;
				    case 6: r = '六倍'; break;
				    default: break;
				}
				return `抽到${color}概率${r}`;
			},
			navBack(){
				uni.navigateBack({
					delta:1
				})
			},
		}
	}
</script>

<style>
	@import url("./light.css");
	.achievement-back-btn {
	    
	    top: 1rem;
	}
</style>
